<script setup>
// #region 引入包, 函数和组件
import { ref } from "vue";
import { useRouter } from "vue-router"; // 路由
// #endregion

// #region // 使用模块(仓库、路由、父组件参数函数)
const router = useRouter();
// #endregion

// #region // 变量
const accountName = ref(""); // 用户账号
const password = ref(""); // 用户密码
// #endregion

// #region // 函数
const onLogin = () => {
  // console.log(accountName.value, password.value);
  if (!accountName.value) return alert("用户名不能为空!");
  if (accountName.value !== "admin") return alert("用户名不正确!");
  if (!password.value) return alert("密码不能为空!");
  if (password.value !== "123") return alert("密码不正确!");
    localStorage.setItem(
      "token",
      `pass => accountName: ${accountName.value};password: ${password.value};`
    );
  router.replace({ name: "home" });
};
// #endregion

// #region // 生命周期和vue函数

// #endregion
</script>

<template>
  <div class="login">
    <ul class="box">
      <li><input v-model="accountName" type="text" placeholder="账号" /></li>
      <li><input v-model="password" type="password" placeholder="密码" /></li>
      <li><button @click="onLogin">登陆</button></li>
    </ul>
  </div>
</template>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #78addc, #2e60cb);
  display: flex;

  .box {
    width: 400px;
    height: 400px;
    border-radius: 8px;
    background: #fff;
    margin: auto 300px auto auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    flex-direction: column;
  }

  li {
    height: 50px;
    margin: 20px 0;
  }

  input,
  button {
    width: 100%;
    height: 100%;
    font-size: 16px;
    border-radius: 6px;
    border: none;
    outline: none;
  }

  input {
    padding-left: 20px;
    border: 1px solid #dedede;

    &::placeholder {
      color: #c5c4c7;
    }

    &:focus {
      outline: 2px solid #333;
    }
  }

  button {
    background: #379bff;
    color: #d3ffff;

    &:hover {
      color: #eee;
      background: #3871d6;
    }

    &:active {
      background: #001a8b;
    }
  }
}
</style>
